package com.framework.loippi.utils.tool;

import com.framework.loippi.entity.Category;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName CategoryUtils
 * @Description TODO
 * @Author fsociety
 * @Date 13/12/2019 上午10:56
 * @Version 1.0
 */
public class CategoryUtils {

    /**
     * 药房树菜单处理(菜单id，nativeList(所有菜单数据))
     * @param id
     * @param nativeList
     * @return
     */
    public static List<Category> getSub(Long id, List<Category> nativeList) {
        List<Category> subList = new ArrayList<Category>();
        for (Category o : nativeList) {
            if (o.getParentId().equals(id)) {
                subList.add(o);
            }
        }

        for (Category p : subList) {
            p.setSubList(getSub(p.getId(), nativeList));
        }

        if (subList.size() == 0) {
            return new ArrayList<Category>();
        }

        return subList;
    }
}
